/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.spielo.crystaldesigner.dao;

import com.spielo.crystaldesigner.property.PropertyHolder;
import java.io.File;
import java.util.ArrayList;
import java.util.Vector;

/**
 *
 * @author Bernhard Reads all screens from the folder
 */
public class ScreenReader {

    private PropertyHolder properties = PropertyHolder.getInstance();

    public Vector<String> getSubfolderList() {
        String pathToPackage = (String) properties.getProperty("path");
        String pathToScreens = pathToPackage + File.separator + "Resources" + File.separator + "Xaml";
        Vector<String> list = new Vector<>();
        list.add("root");
        File screenFolder = new File(pathToScreens);
        File[] content = screenFolder.listFiles();
        System.out.println(screenFolder);
        for (File f : content) {
            if (f.isDirectory()) {
                list.add(f.getName());
            }
        }


        return list;
    }

    public Vector<String> getScreenList(String subfolder) {
        String pathToPackage = (String) properties.getProperty("path");
        String pathToScreens = pathToPackage + File.separator + "Resources" + File.separator + "Xaml";
        Vector<String> list = new Vector<>();

        String path = "";

        if (!subfolder.equals("root") && subfolder.length() > 0) {
            path = pathToScreens + File.separator + subfolder;
        } else {
            path = pathToScreens;
        }


        File screenFolder = new File(path);

        File[] content = screenFolder.listFiles();

        for (File f : content) {
            if (f.getAbsolutePath().endsWith(".xaml")) {
                String name = f.getName();
                name = name.substring(0, name.lastIndexOf("."));
                list.add(name);
            }
        }


        return list;
    }


}
